package org.shock.ss.sms.commons.utils;

import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.Properties;
import org.apache.log4j.Logger;

public class NavProcess {
	private static Logger log = Logger.getLogger(NavProcess.class);
	private static Properties p = new Properties();
	static {
		try {
			p.loadFromXML(Thread.currentThread().getContextClassLoader()
					.getResourceAsStream("nav.xml"));
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	public static String process(String nav)
			throws UnsupportedEncodingException {
		String[] arr = nav.split("\\.");
		StringBuffer sb = new StringBuffer();
		for (int i = 0; i < arr.length; i++) {
			if (p.getProperty(arr[i]) != null
					&& !"".equals(p.getProperty(arr[i]))) {
				sb.append("<a href=" + p.getProperty(arr[i] + ".url") + ">"
						+ p.getProperty(arr[i]) + "</a>>");
			}
		}
		if (sb.lastIndexOf(">") > 0) {
			sb.deleteCharAt(sb.lastIndexOf(">"));
		}
		return sb.toString();
	}
}
